package com.snow.useviewdemo.util;

import android.view.View;

/**
 * author : fancy
 * e-mail : fancheng@ttsing.com
 * date   : 2018/12/17下午2:30
 * desc   :  防多次点击，替换系统的click事件
 * version: 1.0
 */
public abstract class OnAntiDoubleClickListener implements View.OnClickListener{
    // 两次点击按钮之间的点击间隔不能少于1000毫秒
    private static final int MIN_CLICK_DELAY_TIME = 700;
    private static long lastClickTime;

    public abstract void onAntiDoubleClick(View v);

    @Override
    public void onClick(View v) {
        long curClickTime = System.currentTimeMillis();
        if((curClickTime - lastClickTime) >= MIN_CLICK_DELAY_TIME) {
            // 超过点击间隔后再将lastClickTime重置为当前点击时间
            lastClickTime = curClickTime;
            onAntiDoubleClick(v);
        }
    }
}